import 'package:flutter/material.dart';
import 'package:flutter_chip/config/Routers.dart';
import 'package:flutter_chip/utils/toast_utils.dart';

class InputPage extends StatefulWidget {
  int max;

  InputPage({this.max});

  @override
  _InputPageState createState() => _InputPageState();
}

class _InputPageState extends State<InputPage> {
  var _inputController = TextEditingController();

  @override
  void initState() {
    super.initState();
    _inputController.value = TextEditingValue();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: true,
        elevation: 1.0,
        backgroundColor: Theme.of(context).canvasColor,
        actions: <Widget>[
          FlatButton(
              onPressed: () => _submit(),
              child: Text(
                '保存',
                style: TextStyle(fontSize: 16),
              ),
              disabledTextColor: Color(0xff999999))
        ],
      ),
      body: Container(
        padding: EdgeInsets.all(10),
        child: TextField(
          controller: _inputController,
          maxLength: widget.max ?? 100,
        ),
      ),
    );
  }

  _submit() {
    String value = _inputController.text;
    if (null == value || value.isEmpty) {
      Toast.show("输入不能为空");
      return;
    }
    Navigator.pop(context, value);
  }
}
